package com.smarthealthring.mm.utils;

import android.text.TextUtils;

import java.text.DecimalFormat;

/**
 * Created by sun on 17-11-17.
 */

public class FormatUtils {

    public static int str2int(String str) {
        int i;
        try {
            i = Integer.parseInt(str);
        } catch (NumberFormatException e) {
            i = 0;
        }
        return i;
    }

    public static float str2Float(String str) {
        float i;
        try {
            i = Float.parseFloat(str);
        } catch (NumberFormatException e) {
            i = 0;
        }
        return i;
    }

    public static double strDouble(String str) {
        double i;
        try {
            i = Double.parseDouble(str);
        } catch (NumberFormatException e) {
            i = 0;
        }
        return i;
    }

    public static String checkNull(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        return str.trim();
    }

    public static String formatPrice(double price) {
        DecimalFormat df = new DecimalFormat("#.##");
        return df.format(price) + "万";
    }
}
